SlideShare a Scribd company logo
1 of 55
Class No.15  Data Structures http://ecomputernotes.com
Level-order Traversal ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Level-order Traversal Level-order: 14 4 15 3 9 18 7 16 20 5 17 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() )  { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
Level-order Traversal Queue: 14 Output: 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 4 15 Output: 14 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 15 3 9 Output: 14 4 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 3 9 18 Output: 14 4 15 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 9 18 Output: 14 4 15 3  14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 18 7 Output: 14 4 15 3 9  14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 7 16 20 Output: 14 4 15 3 9 18  14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 16 20 5 Output: 14 4 15 3 9 18 7  14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 20 5 17 Output: 14 4 15 3 9 18 7 16  14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 5 17 Output: 14 4 15 3 9 18 7 16 20  14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: 17 Output: 14 4 15 3 9 18 7 16 20 5  14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Level-order Traversal Queue: Output: 14 4 15 3 9 18 7 16 20 5 17 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
Storing other Type of Data ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;,  &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ )  insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;,  &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ )  insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;,  &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ )  insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;,  &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ )  insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;,  &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ )  insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
Binary Search Tree with Strings if( strcmp(info, p->getInfo()) == 0 ){ cout << &quot;attempt to insert duplicate: &quot; << *info  << endl; delete node; } else if( strcmp(info, p->getInfo()) < 0 ) p->setLeft( node ); else p->setRight( node );  }  http://ecomputernotes.com
Binary Search Tree with Strings if( strcmp(info, p->getInfo()) == 0 ){ cout << &quot;attempt to insert duplicate: &quot; << *info  << endl; delete node; } else if( strcmp(info, p->getInfo()) < 0 ) p->setLeft( node ); else p->setRight( node );  }  http://ecomputernotes.com
Binary Search Tree with Strings if( strcmp(info, p->getInfo()) == 0 ){ cout << &quot;attempt to insert duplicate: &quot; << *info  << endl; delete node; } else if( strcmp(info, p->getInfo()) < 0 ) p->setLeft( node ); else p->setRight( node );  }  http://ecomputernotes.com
Binary Search Tree with Strings ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Binary Search Tree with Strings abandon abash accuse adhere advise babble backup bandit cease chain daily debunk eagle economy fable feeder fetch gain genius jacket ,[object Object],http://ecomputernotes.com
Binary Search Tree with Strings abandon abash accuse adhere advise babble backup bandit cease chain daily debunk eagle economy fable feeder fetch gain genius jacket ,[object Object],[object Object],http://ecomputernotes.com
Binary Search Tree with Strings abandon abash accuse adhere advise babble backup bandit cease chain daily debunk eagle economy fable feeder fetch gain genius jacket ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Binary Search Tree with Strings abandon abash accuse adhere advise babble backup bandit cease chain daily debunk eagle economy fable feeder fetch gain genius jacket ,[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Binary Search Tree with Strings abandon abash accuse adhere advise babble backup bandit cease chain daily debunk eagle economy fable feeder fetch gain genius jacket ,[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Binary Search Tree with Strings abandon abash accuse adhere advise babble backup bandit cease chain daily debunk eagle economy fable feeder fetch gain genius jacket ,[object Object],[object Object],[object Object],[object Object],[object Object],http://ecomputernotes.com
Deleting a node in BST ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Deleting a node in BST ,[object Object],6 2 4 3 1 8 http://ecomputernotes.com
Deleting a node in BST ,[object Object],6 2 4 3 1 8 6 2 4 3 1 8  http://ecomputernotes.com
Deleting a node in BST ,[object Object],6 2 4 3 1 8 6 2 4 3 1 8 6 2 3 1 8   http://ecomputernotes.com
Deleting a node in BST ,[object Object],[object Object],http://ecomputernotes.com
Deleting a node in BST Delete(2): locate inorder successor 6 2 5 3 1 8 4 Inorder  successor http://ecomputernotes.com
Deleting a node in BST Delete(2): locate inorder successor 6 2 5 3 1 8 4 Inorder  successor ,[object Object],[object Object],http://ecomputernotes.com
Deleting a node in BST Delete(2): copy data from inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
Deleting a node in BST Delete(2): remove the inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
Deleting a node in BST Delete(2)  6 3 5 4 1 8  6 3 5 3 1 8 4 http://ecomputernotes.com

More Related Content

Similar to computer notes - Data Structures - 15

computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14ecomputernotes
 
Computer notes - Recursive
Computer notes  - RecursiveComputer notes  - Recursive
Computer notes - Recursiveecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13ecomputernotes
 
State Machines to State of the Art
State Machines to State of the ArtState Machines to State of the Art
State Machines to State of the ArtRowan Merewood
 
Arduino section programming slides
Arduino section programming slidesArduino section programming slides
Arduino section programming slidesvivek k
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart PointersCarlo Pescio
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3kitthod
 
Arduino sectionprogramming slides
Arduino sectionprogramming slidesArduino sectionprogramming slides
Arduino sectionprogramming slidesJorge Joens
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16ecomputernotes
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象勇浩 赖
 
MCE^3 - Hannes Verlinde - Let The Symbols Do The Work
MCE^3 - Hannes Verlinde - Let The Symbols Do The WorkMCE^3 - Hannes Verlinde - Let The Symbols Do The Work
MCE^3 - Hannes Verlinde - Let The Symbols Do The WorkPROIDEA
 
Computer notes - Hashing
Computer notes - HashingComputer notes - Hashing
Computer notes - Hashingecomputernotes
 

Similar to computer notes - Data Structures - 15 (20)

computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14
 
Computer notes - Recursive
Computer notes  - RecursiveComputer notes  - Recursive
Computer notes - Recursive
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Php Sq Lite
Php Sq LitePhp Sq Lite
Php Sq Lite
 
Php My Sql
Php My SqlPhp My Sql
Php My Sql
 
State Machines to State of the Art
State Machines to State of the ArtState Machines to State of the Art
State Machines to State of the Art
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Oscon 2010 Specs talk
Oscon 2010 Specs talkOscon 2010 Specs talk
Oscon 2010 Specs talk
 
Arduino section programming slides
Arduino section programming slidesArduino section programming slides
Arduino section programming slides
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers
 
Groovy
GroovyGroovy
Groovy
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3
 
Arduino sectionprogramming slides
Arduino sectionprogramming slidesArduino sectionprogramming slides
Arduino sectionprogramming slides
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
MCE^3 - Hannes Verlinde - Let The Symbols Do The Work
MCE^3 - Hannes Verlinde - Let The Symbols Do The WorkMCE^3 - Hannes Verlinde - Let The Symbols Do The Work
MCE^3 - Hannes Verlinde - Let The Symbols Do The Work
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Computer notes - Hashing
Computer notes - HashingComputer notes - Hashing
Computer notes - Hashing
 

More from ecomputernotes

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraintsecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functionsecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueriesecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objectsecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueriesecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functionsecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36ecomputernotes
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clauseecomputernotes
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Dataecomputernotes
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statementsecomputernotes
 

More from ecomputernotes (20)

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Data
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statements
 

Recently uploaded

The Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and UncertaintyThe Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and Uncertaintycapivisgroup
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon investment
 
Progress Report - Oracle's OCI Analyst Summit 2024
Progress Report - Oracle's OCI Analyst Summit 2024Progress Report - Oracle's OCI Analyst Summit 2024
Progress Report - Oracle's OCI Analyst Summit 2024Holger Mueller
 
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdfThe Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdfbelieveminhh
 
Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312LR1709MUSIC
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPanhandleOilandGas
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptxRoofing Contractor
 
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptxGoal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptxNetapsFoundationAdmi
 
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR ESCORTS SERVICE PROVIDE
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR  ESCORTS SERVICE PROVIDEJAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR  ESCORTS SERVICE PROVIDE
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR ESCORTS SERVICE PROVIDEkajalroy875762
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfwill854175
 
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdfciolook1
 
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...yulianti213969
 
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptxThompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptxtmthompson1
 
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDEJIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDEkajalroy875762
 
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdfProgress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdfHolger Mueller
 
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deck
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deckPitch Deck Teardown: Goodcarbon's $5.5m Seed deck
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deckHajeJanKamps
 
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...ssuserf63bd7
 
Moradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in PenacovaMoradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in Penacovaimostorept
 
2024 May - Clearbit Integration with Hubspot - Greenville HUG.pptx
2024 May - Clearbit Integration with Hubspot  - Greenville HUG.pptx2024 May - Clearbit Integration with Hubspot  - Greenville HUG.pptx
2024 May - Clearbit Integration with Hubspot - Greenville HUG.pptxBoundify
 

Recently uploaded (20)

The Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and UncertaintyThe Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and Uncertainty
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Progress Report - Oracle's OCI Analyst Summit 2024
Progress Report - Oracle's OCI Analyst Summit 2024Progress Report - Oracle's OCI Analyst Summit 2024
Progress Report - Oracle's OCI Analyst Summit 2024
 
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdfThe Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
The Vietnam Believer Newsletter_May 13th, 2024_ENVol. 007.pdf
 
Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptxGoal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
 
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR ESCORTS SERVICE PROVIDE
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR  ESCORTS SERVICE PROVIDEJAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR  ESCORTS SERVICE PROVIDE
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR ESCORTS SERVICE PROVIDE
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdf
 
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
 
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
 
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptxThompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
 
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDEJIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
JIND CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JIND ESCORTS SERVICE PROVIDE
 
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdfProgress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
 
Home Furnishings Ecommerce Platform Short Pitch 2024
Home Furnishings Ecommerce Platform Short Pitch 2024Home Furnishings Ecommerce Platform Short Pitch 2024
Home Furnishings Ecommerce Platform Short Pitch 2024
 
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deck
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deckPitch Deck Teardown: Goodcarbon's $5.5m Seed deck
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deck
 
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
Understanding Financial Accounting 3rd Canadian Edition by Christopher D. Bur...
 
Moradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in PenacovaMoradia Isolada com Logradouro; Detached house with patio in Penacova
Moradia Isolada com Logradouro; Detached house with patio in Penacova
 
2024 May - Clearbit Integration with Hubspot - Greenville HUG.pptx
2024 May - Clearbit Integration with Hubspot  - Greenville HUG.pptx2024 May - Clearbit Integration with Hubspot  - Greenville HUG.pptx
2024 May - Clearbit Integration with Hubspot - Greenville HUG.pptx
 

computer notes - Data Structures - 15

  • 1. Class No.15 Data Structures http://ecomputernotes.com
  • 2.
  • 3. Level-order Traversal Level-order: 14 4 15 3 9 18 7 16 20 5 17 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 4.
  • 5. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 6. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 7. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 8. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 9. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 10. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 11. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 12. Level-order Traversal void levelorder(TreeNode<int>* treeNode) { Queue<TreeNode<int>* > q; if( treeNode == NULL ) return; q.enqueue( treeNode); while( !q.empty() ) { treeNode = q.dequeue(); cout << *(treeNode->getInfo()) << &quot; &quot;; if(treeNode->getLeft() != NULL ) q.enqueue( treeNode->getLeft()); if(treeNode->getRight() != NULL ) q.enqueue( treeNode->getRight()); } cout << endl; }  http://ecomputernotes.com
  • 13. Level-order Traversal Queue: 14 Output: 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 14. Level-order Traversal Queue: 4 15 Output: 14 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 15. Level-order Traversal Queue: 15 3 9 Output: 14 4 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 16. Level-order Traversal Queue: 3 9 18 Output: 14 4 15 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 17. Level-order Traversal Queue: 9 18 Output: 14 4 15 3 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 18. Level-order Traversal Queue: 18 7 Output: 14 4 15 3 9 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 19. Level-order Traversal Queue: 7 16 20 Output: 14 4 15 3 9 18 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 20. Level-order Traversal Queue: 16 20 5 Output: 14 4 15 3 9 18 7 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 21. Level-order Traversal Queue: 20 5 17 Output: 14 4 15 3 9 18 7 16 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 22. Level-order Traversal Queue: 5 17 Output: 14 4 15 3 9 18 7 16 20 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 23. Level-order Traversal Queue: 17 Output: 14 4 15 3 9 18 7 16 20 5 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 24. Level-order Traversal Queue: Output: 14 4 15 3 9 18 7 16 20 5 17 14 4 9 7 3 5 15 18 16 20 17 http://ecomputernotes.com
  • 25.
  • 26. Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;, &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ ) insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
  • 27. Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;, &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ ) insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
  • 28. Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;, &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ ) insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
  • 29. Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;, &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ ) insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
  • 30. Binary Search Tree with Strings void wordTree() { TreeNode<char>* root = new TreeNode<char>(); static char* word[] = &quot;babble&quot;, &quot;fable&quot;, &quot;jacket&quot;, &quot;backup&quot;, &quot;eagle&quot;,&quot;daily&quot;,&quot;gain&quot;,&quot;bandit&quot;,&quot;abandon&quot;, &quot;abash&quot;,&quot;accuse&quot;,&quot;economy&quot;,&quot;adhere&quot;,&quot;advise&quot;,&quot;cease&quot;, &quot;debunk&quot;,&quot;feeder&quot;,&quot;genius&quot;,&quot;fetch&quot;,&quot;chain&quot;, NULL}; root->setInfo( word[0] ); for(i=1; word[i]; i++ ) insert(root, word[i] ); inorder( root ); cout << endl; }  http://ecomputernotes.com
  • 31. Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
  • 32. Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
  • 33. Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
  • 34. Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
  • 35. Binary Search Tree with Strings void insert(TreeNode<char>* root, char* info) { TreeNode<char>* node = new TreeNode<char>(info); TreeNode<char> *p, *q; p = q = root; while( strcmp(info, p->getInfo()) != 0 && q != NULL ) { p = q; if( strcmp(info, p->getInfo()) < 0 ) q = p->getLeft(); else q = p->getRight(); }  http://ecomputernotes.com
  • 36. Binary Search Tree with Strings if( strcmp(info, p->getInfo()) == 0 ){ cout << &quot;attempt to insert duplicate: &quot; << *info << endl; delete node; } else if( strcmp(info, p->getInfo()) < 0 ) p->setLeft( node ); else p->setRight( node ); }  http://ecomputernotes.com
  • 37. Binary Search Tree with Strings if( strcmp(info, p->getInfo()) == 0 ){ cout << &quot;attempt to insert duplicate: &quot; << *info << endl; delete node; } else if( strcmp(info, p->getInfo()) < 0 ) p->setLeft( node ); else p->setRight( node ); }  http://ecomputernotes.com
  • 38. Binary Search Tree with Strings if( strcmp(info, p->getInfo()) == 0 ){ cout << &quot;attempt to insert duplicate: &quot; << *info << endl; delete node; } else if( strcmp(info, p->getInfo()) < 0 ) p->setLeft( node ); else p->setRight( node ); }  http://ecomputernotes.com
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51. Deleting a node in BST Delete(2): locate inorder successor 6 2 5 3 1 8 4 Inorder successor http://ecomputernotes.com
  • 52.
  • 53. Deleting a node in BST Delete(2): copy data from inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
  • 54. Deleting a node in BST Delete(2): remove the inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
  • 55. Deleting a node in BST Delete(2)  6 3 5 4 1 8  6 3 5 3 1 8 4 http://ecomputernotes.com

Editor's Notes

  1. End of lecture 14
  2. Start lecture 16
  3. End of lecture 15